define([
  'jquery',
  'underscore',
  'backbone',
  'dateformatter',
  'models/admin/UnattendedModel',
  'collections/admin/UnattendedCollection',
  'views/admin/UnattendedListView',
  'text!templates/admin/unattendedTemplate.html'
], function($, _, Backbone,Dateformatter, UnattendedModel, UnattendedCollection, UnattendedListView, unattendedTemplate){

  var UnattendedView = Backbone.View.extend({
    el: $(".mainpanel"),
    events: {'click #savePayments' : 'savePayments', 'change .paymentamount':'addtomodel'} ,
    render: function(){
    	this.$el.html(unattendedTemplate);
        var unattendedCollection = new UnattendedCollection();
        var lOptions = {};
        var self=this;
        lOptions.success = function(){
        	var unattendedListView = new UnattendedListView({ collection: unattendedCollection});
        	unattendedListView.render();
        	self.unattendedListView =unattendedListView; 
        };
        unattendedCollection.fetch(lOptions);
    },
    savePayments: function(){
    	//console.log(this.unattendedListView.collection);
    	this.unattendedListView.collection.save();
 		 $.msgBox({
			    title:"Appment",
			    content:"Successfully Saved!",
			    type:"info"
			});
    },
    addtomodel: function(evt){
    	var changed=evt.currentTarget;
    	var model = this.unattendedListView.collection.get(changed.id);
    	console.log(model);
    	model.set("amountPaid",parseFloat($("#"+changed.id).val()));
    	console.log(model);
    }
  });

  return UnattendedView;
});
